import type { Model } from 'dva';
import type { Reducer } from 'umi';

export type GlobalModelState = {
  theme: string;
  lang: string;
  [key: string]: any;
};

export interface GlobalModelType extends Model {
  namespace: 'global';
  state: GlobalModelState;
  reducers: {
    update: Reducer<GlobalModelState>;
  };
}

const global: GlobalModelType = {
  namespace: 'global',
  state: {
    theme: 'default',
    lang: 'zh-CN',
  },
  reducers: {
    update(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};

export default global;
